package ConnectionTCP.com;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import process.*;

public class ConnectionTCPActivity extends Activity {
    /** Called when the activity is first created. */
	Button ConnectTCP;
	Button ConnectUDP;
	Button Disconnect;
	TextView KetQua;
	private String tt ="";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ConnectTCP = (Button)findViewById(R.id.btn_ConnectTCP);
        ConnectUDP = (Button)findViewById(R.id.btn_ConnectUPD);
        KetQua = (TextView)findViewById(R.id.tv_HienThi);
        
        // sự kiện
        ConnectUDP.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				
				
				 UDPClient udp = new UDPClient();
				 tt = "UPD";
				 String b = udp.KetNoi(tt);
				 KetQua.setText(b);
				 if(b.equals("Thành Công"))
				{
					Intent intent = new Intent();
			    	intent.setClass(getBaseContext(),RemotePowerPoint.class);
					startActivity(intent);
					
				}
				
			}
		}); 
        
        ConnectTCP.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				tt = "TCP";	
				TCPClient tcp = new TCPClient();
				String a =tcp.KetNoi(tt);
				KetQua.setText(a);
				if(a.equals("Thành Công"))
				{
					Intent intent = new Intent();
			    	intent.setClass(getBaseContext(),RemotePowerPoint.class);
			    	//intent.putExtra("Giao", tt);
					startActivity(intent);
					
				}
				
				 
			}
		});
        Disconnect = (Button)findViewById(R.id.btn_DisConnect);
        Disconnect.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(tt.equals("UPD"))
				{
					tt = "Disconect";
					UDPClient udp = new UDPClient();
					 String b = udp.KetNoi(tt);
					 KetQua.setText(b);
					
				}
				else
				{
					tt = "Disconect";
					TCPClient tcp = new TCPClient();
					String a =tcp.KetNoi(tt);
					KetQua.setText(a);
				}
				
			}
		});
    }
    
    
   
}